<template>
  <el-dialog
    title="新增用户"
    :visible.sync="visible"
    :close-on-click-modal="false"
    top="8vh"
    width="30%"
  >
    <this-form ref="form" />
    <div slot="footer" class="">
      <el-button class="px-12" type="primary" @click="onSubmit"
        >确 定</el-button
      >
      <el-button class="px-12" plain @click="visible = false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import thisForm from "./form.vue";

export default {
  components: { thisForm },
  data() {
    return {
      visible: false,
    };
  },
  methods: {
    open() {
      this.visible = true;
      this.$nextTick(() => {
        this.$refs.form.init({
          address: "",
          checked: null,
          company: "",
          // createTime: ,
          displayName: "",
          dt: null,
          email: "",
          extra: "",
          gender: "0",
          // id: 249,
          mobile: "",
          name: "",
          passwdMd5: "",
          password: "",
          phone: "",
          portrait: "",
          salt: "",
          social: "",
          type: 0,
          uid: "",
          user: null,
          userId: "",
          userStatus: 0,
        });
      });
    },
    onSubmit() {
      this.$refs.form.validate((form) => {
        this.axios.post(`/user/create`, form).then((res) => {
          if (res.retCode != 0) {
            return this.$message.error(res.retMsg);
          }
          this.$emit("added");
          this.$message.success("操作成功!");
          this.visible = false;
        });
      });
    },
  },
};
</script>